#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct student{
    char name[15];
    char id[15];
    int score;
    
    bool operator < (const student &that) const{
        return score < that.score;
    }
}student[105];

int main()
{
    int N = 0;
    scanf("%d", &N);
    
    for(int i = 0; i < N; i++){
        scanf("%s %s %d", student[i].name, student[i].id, &student[i].score);
    }
    //从大到小排序
    sort(student, student+N);
    printf("%s %s\n", student[N - 1].name, student[N - 1].id);
    printf("%s %s\n", student[0].name, student[0].id);
}
